package com.wm.machine.baselibrary.utils;

import android.content.Context;
import android.widget.Toast;

/**
 * Author： cxp
 * CreatTime： 2016/11/24
 * ContactInfo：
 * Description: Toast tools
 */
public final class ToastUtils {
  private static boolean isShow = true;
  private static Toast mToast;

  private ToastUtils() {
    throw new UnsupportedOperationException("ToastUtils cannot be instantiated");
  }

  /**
   * 全局控制展示
   *
   * @param context 上下文
   * @param message 展示的文字
   */
  public static void showLongControl(Context context, String message) {
    if (isShow) {
      if (null == mToast) {
        mToast = Toast.makeText(context, message, Toast.LENGTH_LONG);
      } else {
        mToast.setText(message);
      }
      mToast.show();
    }
  }

  /** 
   *
   * @param context context
   * @param message 显示内容
   */
  public static void showShortControl(Context context, String message) {
    if (isShow) {
      if (null == mToast) {
        mToast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
      } else {
        mToast.setText(message);
      }
      mToast.show();
    }
  }

  /**
   * @param context context
   * @param message 展示的文字
   * @param duration 自定义展示时间
   */
  public static void showCustomControl(Context context, String message, int duration) {
    if (isShow) {
      if (null == mToast) {
        mToast = Toast.makeText(context, message, duration);
      } else {
        mToast.setText(message);
      }
      mToast.show();
    }
  }

  /**
   * @param context context
   * @param resId 资源id
   */
  public static void showLongControl(Context context, int resId) {
    if (isShow) {
      if (null == mToast) {
        mToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
      } else {
        mToast.setText(resId);
      }
      mToast.show();
    }
  }

  /**
   * @param context context
   * @param resId 资源id
   */
  public static void showShortControl(Context context, int resId) {
    if (isShow) {
      if (null == mToast) {
        mToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
      } else {
        mToast.setText(resId);
      }
      mToast.show();
    }
  }

  /**
   *
   * @param context context
   * @param resId  资源id
   * @param duration 显示时间
   */
  public static void showCustomControl(Context context, int resId, int duration) {
    if (isShow) {
      if (null == mToast) {
        mToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
      } else {
        mToast.setText(resId);
      }
      mToast.show();
    }
  }

  /**
   * @param context context
   * @param message 显示内容
   */
  public static void showLong(Context context, String message) {
    if (null == mToast) {
      mToast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    } else {
      mToast.setText(message);
    }
    mToast.show();
  }

  /** 
   *
   * @param context context
   * @param message 显示内容
   */
  public static void showShort(Context context, String message) {
    if (null == mToast) {
      mToast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    } else {
      mToast.setText(message);
    }
    mToast.show();
  }

  /** 
   *
   * @param context context
   * @param message 消息内容
   * @param duration 显示时间
   */
  public static void showCustom(Context context, String message, int duration) {
    if (null == mToast) {
      mToast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    } else {
      mToast.setText(message);
    }
    mToast.show();
  }

    /**
     * @param context context
     * @param resId 资源id
     */
  public static void showLong(Context context, int resId) {
    if (null == mToast) {
      mToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
    } else {
      mToast.setText(resId);
    }
    mToast.show();
  }

  /**
   * @param context context
   * @param resId 资源id
   */
  public static void showShort(Context context, int resId) {
    if (null == mToast) {
      mToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
    } else {
      mToast.setText(resId);
    }
    mToast.show();
  }

  /**
   * @param context context
   * @param resId 资源ID
   * @param duration 显示时间
   */
  public static void showCustom(Context context, int resId, int duration) {
    if (null == mToast) {
      mToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
    } else {
      mToast.setText(resId);
    }
    mToast.show();
  }

}
